package com.tom.joke.library;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class ImageUtil {

    public static void compressImage(Bitmap bitmap, int quality, String fileName) {
//        compressImage(bitmap, quality, fileName);
    }

    // fileName压缩后的路径，quality压缩质量，bitmap原图片。
//    public native static  int compressImage(Bitmap bitmap, int quality, String fileName);

    // 避免内存OOM
    public static Bitmap decodeFile(String path) {
        int finalWidth = 800; // 预期图片宽度800px，微信是960px
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true; // 只拿到宽高
        BitmapFactory.decodeFile(path, options);

        int bitmapWidth = options.outWidth; // 图片宽度
        int inSampleSize = 1;
        if (bitmapWidth > finalWidth) {
            inSampleSize = bitmapWidth / finalWidth;
        }
        options.inSampleSize = inSampleSize; // 缩放比例
        options.inJustDecodeBounds = false;
        return BitmapFactory.decodeFile(path, options);
    }
}
